/**
 * output package name
 */
package com.kingdee.eas.custom.hr.attendance.client;

import java.awt.event.ActionEvent;
import java.util.Date;
import java.util.HashMap;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.eas.hr.compensation.util.HRUtils;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.util.DateTimeUtils;

/**
 * output class name
 */
public class ImpNaturalMonthUI extends AbstractImpNaturalMonthUI {
	private static final Logger logger = CoreUIObject
			.getLogger(ImpNaturalMonthUI.class);
	private String year = "";
	private String beginMonth = "";
	private String endMonth = "";
	private String lastDate = null;
	private HashMap hashDataValueMap = new HashMap();
	private String cmpPeriodResourceBasicURL = "com.kingdee.eas.hr.compensation.client.CmpPeriodResource.";
	public static final ResourceBundle resouce = ResourceBundle
			.getBundle("com.kingdee.eas.custom.hr.attendance.Config");

	/**
	 * output class constructor
	 */
	public ImpNaturalMonthUI() throws Exception {
		super();
	}

	/**
	 * output storeFields method
	 */
	public void storeFields() {
		super.storeFields();
	}

	/**
	 * output actionPageSetup_actionPerformed
	 */
	public void actionPageSetup_actionPerformed(ActionEvent e) throws Exception {
		super.actionPageSetup_actionPerformed(e);
	}

	/**
	 * output actionExitCurrent_actionPerformed
	 */
	public void actionExitCurrent_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExitCurrent_actionPerformed(e);
	}

	/**
	 * output actionHelp_actionPerformed
	 */
	public void actionHelp_actionPerformed(ActionEvent e) throws Exception {
		super.actionHelp_actionPerformed(e);
	}

	/**
	 * output actionAbout_actionPerformed
	 */
	public void actionAbout_actionPerformed(ActionEvent e) throws Exception {
		super.actionAbout_actionPerformed(e);
	}

	/**
	 * output actionOnLoad_actionPerformed
	 */
	public void actionOnLoad_actionPerformed(ActionEvent e) throws Exception {
		super.actionOnLoad_actionPerformed(e);
	}

	/**
	 * output actionSendMessage_actionPerformed
	 */
	public void actionSendMessage_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionSendMessage_actionPerformed(e);
	}

	/**
	 * output actionCalculator_actionPerformed
	 */
	public void actionCalculator_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionCalculator_actionPerformed(e);
	}

	/**
	 * output actionExport_actionPerformed
	 */
	public void actionExport_actionPerformed(ActionEvent e) throws Exception {
		super.actionExport_actionPerformed(e);
	}

	/**
	 * output actionExportSelected_actionPerformed
	 */
	public void actionExportSelected_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExportSelected_actionPerformed(e);
	}

	/**
	 * output actionRegProduct_actionPerformed
	 */
	public void actionRegProduct_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionRegProduct_actionPerformed(e);
	}

	/**
	 * output actionPersonalSite_actionPerformed
	 */
	public void actionPersonalSite_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionPersonalSite_actionPerformed(e);
	}

	/**
	 * output actionProcductVal_actionPerformed
	 */
	public void actionProcductVal_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionProcductVal_actionPerformed(e);
	}

	/**
	 * output actionExportSave_actionPerformed
	 */
	public void actionExportSave_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExportSave_actionPerformed(e);
	}

	/**
	 * output actionExportSelectedSave_actionPerformed
	 */
	public void actionExportSelectedSave_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExportSelectedSave_actionPerformed(e);
	}

	/**
	 * output actionKnowStore_actionPerformed
	 */
	public void actionKnowStore_actionPerformed(ActionEvent e) throws Exception {
		super.actionKnowStore_actionPerformed(e);
	}

	/**
	 * output actionAnswer_actionPerformed
	 */
	public void actionAnswer_actionPerformed(ActionEvent e) throws Exception {
		super.actionAnswer_actionPerformed(e);
	}

	/**
	 * output actionRemoteAssist_actionPerformed
	 */
	public void actionRemoteAssist_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionRemoteAssist_actionPerformed(e);
	}

	/**
	 * output actionPopupCopy_actionPerformed
	 */
	public void actionPopupCopy_actionPerformed(ActionEvent e) throws Exception {
		super.actionPopupCopy_actionPerformed(e);
	}

	/**
	 * output actionHTMLForMail_actionPerformed
	 */
	public void actionHTMLForMail_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionHTMLForMail_actionPerformed(e);
	}

	/**
	 * output actionExcelForMail_actionPerformed
	 */
	public void actionExcelForMail_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExcelForMail_actionPerformed(e);
	}

	/**
	 * output actionHTMLForRpt_actionPerformed
	 */
	public void actionHTMLForRpt_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionHTMLForRpt_actionPerformed(e);
	}

	/**
	 * output actionExcelForRpt_actionPerformed
	 */
	public void actionExcelForRpt_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionExcelForRpt_actionPerformed(e);
	}

	/**
	 * output actionLinkForRpt_actionPerformed
	 */
	public void actionLinkForRpt_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionLinkForRpt_actionPerformed(e);
	}

	/**
	 * output actionPopupPaste_actionPerformed
	 */
	public void actionPopupPaste_actionPerformed(ActionEvent e)
			throws Exception {
		super.actionPopupPaste_actionPerformed(e);
	}

	/**
	 * output actionCommit_actionPerformed
	 */
	public void actionCommit_actionPerformed(ActionEvent e) throws Exception {
		this.year = this.txtYear.getText();
		this.beginMonth = this.cmbBeginMonth.getSelectedItem().toString();
		this.endMonth = this.cmbEndMonth.getSelectedItem().toString();
		verify();
		this.hashDataValueMap.put("yearKey", this.year);
		this.hashDataValueMap.put("beginMonthKey", this.beginMonth);
		this.hashDataValueMap.put("endMonthKey", this.endMonth);
		this.hashDataValueMap.put("isGenName", new Boolean(this.chkGenName
				.isSelected()));
		disposeUIWindow();
	}

	/**
	 * output actionCancel_actionPerformed
	 */
	public void actionCancel_actionPerformed(ActionEvent e) throws Exception {
		super.actionCancel_actionPerformed(e);
	}

	private void verify() {
		int selectYear = new Integer(this.year).intValue();
		int beginMonth = new Integer(this.beginMonth).intValue();
		int endMonth = new Integer(this.endMonth).intValue();

		if (this.lastDate != null) {
			int lastYear = new Integer(this.lastDate.split("-")[0]).intValue();
			int lastMonth = new Integer(this.lastDate.split("-")[1]).intValue();
			int lastDay = new Integer(this.lastDate.split("-")[2]).intValue();

			Date lastDate = HRUtils.stringConvertToDate("yyyy-MM-dd",
					this.lastDate);
			Date lastDateAdd = DateTimeUtils.addDay(lastDate, 1L);
			String selectDateBeginString = this.year + "-"
					+ (Integer.parseInt(this.beginMonth) - 1) + "-"
					+ resouce.getString("last_month");
			Date selectDateBegin = HRUtils.stringConvertToDate("yyyy-MM-dd",
					selectDateBeginString);
			if (!lastDateAdd.equals(selectDateBegin)) {
				MsgBox.showWarning(EASResource
						.getString(this.cmpPeriodResourceBasicURL
								+ "MUST_CONTINUE_DATE"));
				SysUtil.abort();
			}
			if (lastYear > selectYear) {
				MsgBox.showWarning(EASResource
						.getString(this.cmpPeriodResourceBasicURL
								+ "YEAR_LESS_LASTYEAR"));
				SysUtil.abort();
			} else if ((lastYear == selectYear) && (lastMonth >= beginMonth)) {
				MsgBox.showWarning(EASResource
						.getString(this.cmpPeriodResourceBasicURL
								+ "LASTMONTH_LESS_BEGINMONTH"));
				SysUtil.abort();
			}
		}

		if (endMonth < beginMonth) {
			MsgBox.showWarning(EASResource
					.getString(this.cmpPeriodResourceBasicURL
							+ "BEGINGDATE_LESS_ENDDATE"));
			SysUtil.abort();
		}
	}

	public HashMap getDateValue() {
		return this.hashDataValueMap;
	}

	@Override
	public void onLoad() throws Exception {
		super.onLoad();
		if (getUIContext().get("lastDate") != null) {
			this.lastDate = getUIContext().get("lastDate").toString();
		}
	}
}